<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Created by PhpStorm.
 * User: HP
 * Date: 2017/6/21
 * Time: 10:17
 */

class Goodstype_model extends CI_Model {
    const TBL_CATE = "goods_type";
    public function list_goodstype(){
        $query = $this->db->get(self::TBL_CATE);
        return $query->result_array();
    }
    public function add_goodstype($data){
        return $this->db->insert(self::TBL_CATE, $data);
    }
    //获得单条记录
    public function one_goodstype($type_id){
        $condition['type_id'] = $type_id;
        $query = $this->db->where($condition)->get(self::TBL_CATE);
        return $query->row_array();
    }
    public function update_goodstype($data,$type_id){
        return $this->db->update(self::TBL_CATE, $data, array('type_id' => $type_id));
    }
    //查询类型名称是否重复
    public function find_name($type_name,$type_id){
        $array = array('type_id !=' => $type_id,'type_name' => $type_name);
        $query = $this->db->where($array)->get(self::TBL_CATE);
        return $query->result_array();
    }
    //删除单条数据
    public function delete_oneGoodstype($type_id){
        return $this->db->delete(self::TBL_CATE, array('type_id' => $type_id));
    }

    //获取总的记录数
    public function get_allNum(){
        return $this->db->count_all(self::TBL_CATE);  // Produces an integer, like 25
    }

    //根据指定的页码获取数据
    public function get_pageData($limit,$offset){
        $query = $this->db->limit($limit,$offset)->get(self::TBL_CATE);
        return $query->result_array();
    }
}